package com.solar.etl.util;

import java.util.Hashtable;
import java.util.Iterator;

public class Variable {
	public Variable(){}
	Hashtable<String, String> htParams = new Hashtable<String, String>();
	public Variable(String[] pg){
		if(pg!=null){			
			for (int i = 0; i < pg.length; i++) {
				String key = pg[i].substring(1);
				String value = "";
				++i;
				if(i < pg.length){
					value=pg[i];
				}
				htParams.put(key, value);
			}
		}
	}
	public String getValue(String key){
		return htParams.get(key);
	}
	public String injectVariable(String str){
		for(Iterator itr = htParams.keySet().iterator(); itr.hasNext();){ 
			String key = (String) itr.next(); 
			String value = (String) htParams.get(key); 
			str=str.replaceAll("\\$\\{"+key+"\\}", value);
		} 
		return str;
	}
}
